package formateos;

import java.text.DateFormat;
import java.text.NumberFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Locale;
import java.util.logging.Level;
import java.util.logging.Logger;

public class Main {

    public static void main(String[] args) throws Exception {
        
        
        Date d = pruebasConCalendario();      
        
//        pruebasSimpleDateFormat(d);
//        pruebasFormateoFechaConLocale(d);
        pruebasFormateoNumeros();





    }

    private static Date pruebasConCalendario() {
//        Calendar cal = new GregorianCalendar();
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.DAY_OF_YEAR, 15);
        cal.set(Calendar.YEAR, 1);
        int mes = cal.get(Calendar.MONTH);
        int dia = cal.get(Calendar.DAY_OF_MONTH);
        System.out.println("15 días más es: "+dia+" "+(mes+1));
        Date d = cal.getTime();
        return d;
    }

    private static void pruebasFormateoNumeros() {
        Locale l = new Locale("fr");
        NumberFormat nf = NumberFormat.getNumberInstance(l);
        System.out.println(nf.format(123.45567));
        try {
            Number numero = nf.parse("122,345");
            System.out.println(numero);
        } catch (ParseException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private static void pruebasFormateoFechaConLocale(Date d) {
        Locale l = new Locale("de", "DE");
        {
            DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, l);
            System.out.println(df.format(d));
            try {
                Date reconocida = df.parse("12.15.2006");
                System.out.println(reconocida);
            } catch (ParseException ex) {
                Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        {
            DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM, l);
            System.out.println(df.format(d));
            try {
                Date reconocida = df.parse("12.15.2006");
                System.out.println(reconocida);
            } catch (ParseException ex) {
                Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        {
            DateFormat df = DateFormat.getDateInstance(DateFormat.LONG, l);
            System.out.println(df.format(d));
            try {
                Date reconocida = df.parse("15. April 2010");
                System.out.println(reconocida);
            } catch (ParseException ex) {
                Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        {
            DateFormat df = DateFormat.getDateInstance(DateFormat.FULL, l);
            System.out.println(df.format(d));
            try {
                Date reconocida = df.parse("Mittwoch, 9. April 2008");
                System.out.println(reconocida);
            } catch (ParseException ex) {
                Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        // SHORT  MEDIUM LONG FULL
        {
            DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, l);
            System.out.println(df.format(d));
            try {
                Date reconocida = df.parse("09.04.08 17:06");
                System.out.println(reconocida);
            } catch (ParseException ex) {
                Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }

    private static void pruebasSimpleDateFormat(Date d) {
        SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
        System.out.println(sdf.format(d));
        Date reconocida2;
        try {
            reconocida2 = sdf.parse("12/15/2006");
            System.out.println(reconocida2);
        } catch (ParseException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
